﻿using System;
using System.Linq;
using System.Text;
using System.ComponentModel;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using System.Collections.Generic;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Updating;
using DevExpress.ExpressApp.Model.Core;
using DevExpress.ExpressApp.Model.DomainLogics;
using DevExpress.ExpressApp.Model.NodeGenerators;
using DevExpress.Persistent.BaseImpl;
using aztall.Module.BusinessObjects;
using DevExpress.Data.Filtering;
using System.Windows.Forms;
using DevExpress.ExpressApp.Win.Templates;

namespace aztall.Module.Win
{
	[ToolboxItemFilter("Xaf.Platform.Win")]
	// For more typical usage scenarios, be sure to check out https://documentation.devexpress.com/eXpressAppFramework/clsDevExpressExpressAppModuleBasetopic.aspx.
	public sealed partial class aztallWindowsFormsModule : ModuleBase
	{
		//private void Application_CreateCustomModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) {
		//    e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), true, "Win");
		//    e.Handled = true;
		//}
		private void Application_CreateCustomUserModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e)
		{
			e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), false, "Win");
			e.Handled = true;
		}
		public aztallWindowsFormsModule()
		{
			InitializeComponent();
		}
		public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB)
		{
			return ModuleUpdater.EmptyModuleUpdaters;
		}
		public override void Setup(XafApplication application)
		{
			base.Setup(application);
			//application.CreateCustomModelDifferenceStore += Application_CreateCustomModelDifferenceStore;
			application.CreateCustomUserModelDifferenceStore += Application_CreateCustomUserModelDifferenceStore;
			// Manage various aspects of the application UI and behavior at the module level.
		}
		public override IList<PopupWindowShowAction> GetStartupActions()
		{
			List<PopupWindowShowAction> actions = new List<PopupWindowShowAction>(base.GetStartupActions());
			IObjectSpace os = this.Application.CreateObjectSpace();
			PopupWindowShowAction startupAction = new PopupWindowShowAction();
			//startupAction.CustomizeTemplate += StartupAction_CustomizeTemplate;

			//Domain def = os.FindObject<Domain>(new BinaryOperator("DomainCode", "DEF"));
			startupAction.CustomizePopupWindowParams +=
					delegate (Object sender, CustomizePopupWindowParamsEventArgs e)
					{
						e.View = Application.CreateDetailView(os, "DomainSelector", true, null);
					};
			actions.Add(startupAction);
			return actions;
		}

		//private void StartupAction_CustomizeTemplate(object sender, CustomizeTemplateEventArgs e)
		//{
		//	PopupFormBase form = (PopupFormBase)e.Template;
		//	((PopupFormBase)form).AutoShrink = true;
		//	//((PopupFormBase)form).AutoSizeMode = AutoSizeMode.GrowAndShrink;

		//	form.HandleCreated += (s, args) =>
		//	{
		//		form.InitialMinimumSize = new System.Drawing.Size(100, 80);
		//		form.MinimizeBox = false;
		//		form.MaximizeBox = false;
		//		//form.FormBorderStyle = FormBorderStyle.FixedSingle;
		//	};
		//}
	}
}
